package main

import (
	"fmt"
	"mysql-read-excel/cmd"
	"mysql-read-excel/excel"
	"mysql-read-excel/model"
	"mysql-read-excel/mysql"
)

func main() {

	cmd.InitConfigAndDB()

	MemberMappingIntoDb()

}

// MemberMappingIntoDb 将excel配置加载进数据库
func MemberMappingIntoDb() {

	fileName := "file/member_mapping.xlsx"
	sheetName := "Sheet1"
	rows, err := excel.GetRows(fileName, sheetName)
	if err != nil {
		fmt.Println(err)
		return
	}

	var returnMappingList []*model.TbBsiGroupInterfaceMember
	for idx, row := range rows {
		if idx == 0 {
			//跳过表头
			continue
		}

		if len(row) < 3 {
			fmt.Println("ERROR row: ", row)
			return
		}

		returnMappingList = append(returnMappingList, &model.TbBsiGroupInterfaceMember{
			BG:           row[0],
			BsiGroup:     row[1],
			MemberEnName: row[2],
		})
	}

	//每 100(可设置) 条记录插入一次
	rowAffect := mysql.Get().CreateInBatches(&returnMappingList, 100)
	fmt.Println("RowsAffected=", rowAffect.RowsAffected)
}
